package com.o2o.cleaning.month.platform.ebusiness_plat.kuaishou

import com.alibaba.fastjson.JSON
import org.apache.log4j.{Level, Logger}
import org.apache.spark.rdd.RDD
import org.apache.spark.sql.SQLContext
import org.apache.spark.{SparkConf, SparkContext}

/**
  * @Author: xuechunhua
  * @Date: 2020/6/2 23:35
  * @version 1.0
  */
object back_06_Update_ES_Data {
  def main(args: Array[String]): Unit = {
    Logger.getLogger("org.apache.spark").setLevel(Level.WARN)
    val conf = new SparkConf()
    conf.setAppName(s"${this.getClass.getSimpleName}")
    conf.setMaster("local[*]")
    conf.set("es.nodes", "192.168.1.29")
    conf.set("es.port", "9200")
    conf.set("cluster.name", "O2OElastic")
    conf.set("spark.serializer", "org.apache.spark.serializer.KryoSerializer")
    conf.set("spark.sql.caseSensitive", "true")
    val sc = new SparkContext(conf)
    val sqlContext = new SQLContext(sc)
    sc.setLogLevel("WARN")
    sc.hadoopConfiguration.set("fs.s3a.access.key", "GAO7EO9FWKPJ8WFCQDME")
    sc.hadoopConfiguration.set("fs.s3a.secret.key", "LZ0xaHBSYKHaJ9ECDbX9f7zin79UZkXfGoNapRPL")
    sc.hadoopConfiguration.set("fs.s3a.endpoint", "https://obs.cn-north-1.myhuaweicloud.com")
    /**
      * 天猫
      */

    //    val year = 2021
    //    val month = 7
    // for (months <- 1 to allmonth) {
    //        val index = s"2021_tmall/tmall_2021_10"
    //        val index = s"2021_taobao/taobao_2021_12"
    //    val index = s"2021_miya/miya_2021_8"
    val index = s"2021_kuaishou/kuaishou_2021_12"
    //    val index = s"tmall_2021_activity/tmall_2021_618"
    import org.elasticsearch.spark._


    val sourceDate: RDD[String] = sc.esJsonRDD(s"${index}",
      """
        |  {
        |  "size": 20
        |  , "query": {
        |    "term": {
        |      "good_id": {
        |        "value": "3824209841719"
        |      }
        |    }
        |  }
        |}
         """.stripMargin).values

    val sourcePriceEX = sourceDate.map(line => {

      val nObject = JSON.parseObject(line)
      nObject.put("shopName", "哈药")
      nObject.put("shopUrl", "https://app.kwaixiaodian.com/merchant/shop/list?id=2444959719&webviewClose=false&biz=merchant&carrierType=100010&from=unknown&carrierId=lmnDeQhnyNU&hyId=kwaishop")
      nObject
    }).saveToEs(s"${index}", Map("es.mapping.id" -> "good_id"))
    // }
    sc.stop()

  }
}